package com.power.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.github.pagehelper.PageInfo;
import com.power.model.pojo.Zhiding;
import com.power.service.ZhidingService;

@RestController
@RequestMapping("/xq")
public class ZhidingController {
@Autowired
ZhidingService service;
@RequestMapping("/xqzhiding")
public PageInfo<Zhiding> selectAll(Integer pagenum,Integer pagesize){
	   System.out.println(pagenum+"--"+pagesize);
	 if(pagenum==null)
		 pagenum=1;
  if(pagesize==null)
	  pagesize=2;
    
	List<Zhiding> list =  service.selectAll(pagenum,pagesize);
	for (Zhiding zhiding : list) {
		System.out.println(zhiding.getWcdate());
	}
	PageInfo<Zhiding> pager = new PageInfo<Zhiding>(list);
	return pager;
}
@RequestMapping("/duoiaojian")  //多条件查询
public PageInfo<Zhiding> duotiaojian(String rwname, String rwzt, String xfuser, Date xfdate,
		Date wcdate,Integer pagenum,Integer pagesize){
	if(pagenum==null)
		 pagenum=1;
	if(pagesize==null)
	  pagesize=2;
	System.out.println(",任务名称:"+rwname+",任务状态:"+rwzt+"，下发人："+xfuser+",下发时间："+xfdate+",完成时间："+wcdate);
	System.out.println(pagesize);
	List<Zhiding> list=service.duotiaojian(rwname, rwzt, xfuser, xfdate, wcdate,pagenum,pagesize);
	System.out.println(list.toString());
	PageInfo<Zhiding> pager = new PageInfo<Zhiding>(list);
	return pager;
	
}
//添加
@RequestMapping("/insert")  
public String addZhiding(Integer qx,String rwname,String rwzt,String workdj,String xfuser) {
	System.out.println(qx+"---"+rwname+"--"+rwzt+"--"+workdj+"--"+new Date()+"--"+xfuser);
	Zhiding z=new Zhiding(null,qx,rwname,rwzt,new Date(),workdj,new Date(), xfuser);
	
	service.addZhiding(z);
	if(z.getRwid()!=null&&z.getRwid()>0) {
		return "添加完成"+z.getRwid();
	}else {
		return "添加失败";
	}
	
	
}
//根据编号修改取消状态
@RequestMapping("/updateqx")
public String updateqx(Integer rwid,Integer qx) {
	service.updateqx(rwid, qx);
	return "编号："+rwid+"修改成功";
	
}
//修改
@RequestMapping("/update")  
public String updateZhiding(Zhiding zhiding) {	
	service.updateZhiding(zhiding);
	return "修改成功"+zhiding;
	
	
}

//删除
@RequestMapping("/delete")
public void delete(Integer rwid){
	service.delete(rwid);
	
}
}